package com.leyou.item.controller;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.service.ISpecGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/spec")
public class SpecGroupController {
    @Autowired
    private ISpecGroupService specGroupService;

    /**
     * 根据分类查询规格组,及组内参数
     * @param id
     * @return
     */
    @GetMapping("/of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecsByCid(@RequestParam("id") Long id) {
        return ResponseEntity.ok(specGroupService.querySpecsByCid(id));
    }

    /**
     * 根据分类查询规格组
     * @param id
     * @return
     */
    @GetMapping("/groups/of/category/")
    public ResponseEntity<List<SpecGroupDTO>> queryGroupByCategory(@RequestParam("id")Long id) {
        return ResponseEntity.ok(specGroupService.queryGroupByCategory(id));
    }
}
